<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/19
 * Time: 22:33
 */

namespace app\common\validate;

use app\lib\exception\ParamersException;
use think\Validate;

class BaseValidate extends Validate
{

    //判断是否为正整数
    public function isPositiveInteger($value)
    {
        if(is_numeric($value + 0) && is_int($value + 0) && ($value + 0) > 0) return true;
        return false;
    }
    //判断是否为空
    public function isEmpty($code = '')
    {
        if(empty($code)) return false;
        return true;
    }
    //过滤传递的参数，把不该要的数据删除
    public function getDataByRule($array)
    {
        if(array_key_exists('uid', $array) || array_key_exists('user_id', $array)) throw new ParamersException(['msg' => '传递的参数有致命错误！']);
        //开始过滤
        $ruleArray = [];
        foreach ($this -> rule as $key => $value)
        {
            $ruleArray[$key] = $array[$key];
        }
        return $ruleArray;
    }
    //手机号的验证
    protected function isMobile($value)
    {
        $pattern = '/^1(3|4|5|7|8)[0-9]\d{8}$/';
        $result = preg_match($pattern, $value);
        if(!$result) return false;
        return true;
    }
}